package com.stress.testing.plugin.es.strategy;

import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.bulk.BulkRequest;

import java.util.Iterator;
import java.util.List;

public class BulkRequestIndexRenameStrategy extends AbstractRequestIndexRenameStrategy {
    @Override
    public void renameIndex(Object arg) {
        BulkRequest request = (BulkRequest) arg;
        List<DocWriteRequest<?>> requests = request.requests();
        Iterator<DocWriteRequest<?>> iterator = requests.iterator();
        while (iterator.hasNext()) {
            DocWriteRequest<?> req = iterator.next();
            req.index(internalRenameIndex(req.index()));
        }
    }
}
